<!--正式版 更新时间：2024年3月30日-->
<!--测试版页面：test.php 在域名后面填写即可访问 -->
<!--纯PHP语言编写：php-test.php 在域名后面填写即可访问  -->
<!--你现在看到的代码是正式版，遇到问题欢迎到我们工作室官网 www.xctcn.cn 反馈-->
<!--写代码也想和自己暗恋的人表白！shu畅我喜欢你！-->
<!DOCTYPE html>
<html>
<head>
    <link rel="icon" href="./logo.ico">
    <title>3AMS怀旧歌曲播放器</title>
    <style>
        :root {
            --primary-color: #fc3c44;
            --bg-color: #1c1c1e;
            --card-bg: #2c2c2e;
            --text-primary: #fff;
            --text-secondary: #98989f;
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            background: url(https://api.dujin.org/bing/1920.php) no-repeat center center fixed;
            background-size: cover;
            font-family: -apple-system, "SF Pro SC", "SF Pro Text", "SF Pro Icons",
                "PingFang SC", "Helvetica Neue", "Helvetica", "Arial", sans-serif;
            color: var(--text-primary);
            line-height: 1.5;
        }

        .container {
            position: relative;
            max-width: 1200px;
            margin: 0 auto;
            padding: 20px;
            background: rgba(28, 28, 30, 0.85);
            min-height: 100vh;
            backdrop-filter: blur(20px);
            -webkit-backdrop-filter: blur(20px);
        }

        .header {
            text-align: center;
            padding: 40px 0;
            background: rgba(28, 28, 30, 0.5);
            backdrop-filter: blur(20px);
            -webkit-backdrop-filter: blur(20px);
            border-radius: 16px;
            margin-bottom: 24px;
        }

        .logo {
            width: 80px;
            height: 80px;
            margin: 0 auto 20px;
            border-radius: 16px;
            overflow: hidden;
            box-shadow: 0 8px 24px rgba(0,0,0,0.2);
        }

        .logo img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }

        h1 {
            font-size: 32px;
            font-weight: 600;
            margin-bottom: 8px;
            background: linear-gradient(90deg, var(--primary-color), #fd4d64);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }

        h3 {
            color: var(--text-secondary);
            font-weight: 500;
            font-size: 15px;
        }

        .player-section {
            background: rgba(44, 44, 46, 0.8);
            border-radius: 16px;
            padding: 24px;
            margin: 24px 0;
            backdrop-filter: blur(20px);
            -webkit-backdrop-filter: blur(20px);
            border: 1px solid rgba(255, 255, 255, 0.1);
        }

        #musicPlayer {
            width: 100%;
            height: 36px;
            margin: 20px 0;
            border-radius: 8px;
        }

        .control-buttons {
            display: flex;
            justify-content: center;
            gap: 12px;
            margin: 20px 0;
        }

        .control-buttons button {
            padding: 10px 20px;
            border: none;
            border-radius: 8px;
            background: rgba(255,255,255,0.1);
            color: var(--text-primary);
            font-size: 15px;
            cursor: pointer;
            transition: all 0.3s ease;
        }

        .control-buttons button:hover {
            background: rgba(255,255,255,0.2);
        }

        #playMode {
            padding: 10px;
            border-radius: 8px;
            background: rgba(255,255,255,0.2);
            color: var(--text-primary);
            border: 1px solid rgba(255,255,255,0.2);
            font-size: 15px;
            cursor: pointer;
            appearance: none;
            -webkit-appearance: none;
            -moz-appearance: none;
            padding-right: 30px;
            background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23ffffff' d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
            background-repeat: no-repeat;
            background-position: right 10px center;
        }

        #playMode:hover {
            background-color: rgba(255,255,255,0.3);
        }

        #playMode option {
            background: var(--bg-color);
            color: var(--text-primary);
            padding: 10px;
        }

        .search-bar {
            display: flex;
            gap: 12px;
            margin: 24px 0;
        }

        #searchInput {
            flex: 1;
            padding: 12px 20px;
            border-radius: 8px;
            border: none;
            background: rgba(255,255,255,0.1);
            color: var(--text-primary);
            font-size: 15px;
        }

        #searchInput:focus {
            outline: none;
            background: rgba(255,255,255,0.15);
        }

        #searchButton {
            padding: 12px 24px;
            border: none;
            border-radius: 8px;
            background: var(--primary-color);
            color: white;
            font-size: 15px;
            cursor: pointer;
            transition: all 0.3s ease;
        }

        #searchButton:hover {
            background: #fd4d64;
        }

        .music-container {
            background: rgba(44, 44, 46, 0.8);
            border-radius: 16px;
            padding: 16px;
            height: 500px;
            overflow-y: auto;
            backdrop-filter: blur(20px);
            -webkit-backdrop-filter: blur(20px);
            border: 1px solid rgba(255, 255, 255, 0.1);
        }

        .music-container::-webkit-scrollbar {
            width: 6px;
        }

        .music-container::-webkit-scrollbar-track {
            background: rgba(255,255,255,0.1);
        }

        .music-container::-webkit-scrollbar-thumb {
            background: rgba(255,255,255,0.3);
            border-radius: 3px;
        }

        .music-column {
            padding: 12px 16px;
            margin: 4px 0;
            border-radius: 8px;
            background: rgba(255, 255, 255, 0.05);
            cursor: pointer;
            transition: all 0.3s ease;
            border: 1px solid rgba(255, 255, 255, 0.05);
        }

        .music-column:hover {
            background: rgba(255, 255, 255, 0.1);
            transform: translateX(4px);
            border-color: rgba(255, 255, 255, 0.1);
        }

        .music-column.playing {
            background: rgba(252,60,68,0.15);
            border-left: 4px solid var(--primary-color);
        }

        #currentSong {
            font-size: 16px;
            color: var(--text-primary);
            margin: 12px 0;
            padding: 12px;
            background: rgba(255,255,255,0.05);
            border-radius: 8px;
        }

        @media (max-width: 768px) {
            .container {
                padding: 12px;
            }
            
            .control-buttons {
                flex-wrap: wrap;
            }
            
            .search-bar {
                flex-direction: column;
            }
            
            #searchButton {
                width: 100%;
            }
        }

        .overlay {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(0, 0, 0, 0.3);
            z-index: -1;
        }
    </style>
</head>
<body>
    <div class="overlay"></div>
    <div class="container">
        <div class="header">
            <div class="logo">
                <img src="./3ams.jpg" alt="3AMS Logo">
            </div>
            <h1>3AMS音乐</h1>
            <h3>开源版 V2.1.5</h3>
        </div>

        <div class="player-section">
            <div id="currentSong"></div>
            <audio id="musicPlayer" controls autoplay>
                <source src="" type="audio">
                您的浏览器不支持音频播放。
            </audio>

            <div class="control-buttons">
                <button onclick="playPrevious()">上一首</button>
                <button id="playPauseButton" onclick="togglePlayPause()">播放</button>
                <button onclick="playNext()">下一首</button>
                <select id="playMode" onchange="changePlayMode()">
                    <option value="sequential">顺序播放</option>
                    <option value="random">随机播放</option>
                    <option value="loop">单曲循环</option>
                </select>
                <button onclick="window.location.href='file-php.php'">音乐列表</button>
            </div>
        </div>

        <div class="search-bar">
            <input type="text" id="searchInput" placeholder="搜索音乐...">
            <button id="searchButton" onclick="searchMusic()">搜索</button>
        </div>

        <div class="music-container" id="musicList">
            <?php
            $musicDirectory = './MP3/';
            $musicFiles = array_diff(scandir($musicDirectory), array('..', '.'));

            foreach ($musicFiles as $index => $musicFile) {
                echo '<div class="music-column" data-songname="' . $musicFile . '">' . $musicFile . '</div>';
            }
            ?>
        </div>
    </div>

    <script>
        var musicPlayer = document.getElementById("musicPlayer");
        var playPauseButton = document.getElementById("playPauseButton");
        var currentSong = document.getElementById("currentSong");
        var searchInput = document.getElementById("searchInput");
        var searchResults = document.getElementById("searchResults");
        var musicColumns = document.querySelectorAll('.music-column');
        var playModeSelect = document.getElementById("playMode");
        var currentIndex = localStorage.getItem('currentIndex') || 0;
        var playMode = localStorage.getItem('playMode') || 'sequential';

        // 自动播放下一首
        musicPlayer.addEventListener('ended', function() {
            playNext();
        });

        // 初始化播放模式
        playModeSelect.value = playMode;

        // 点击音乐列播放音乐
        musicColumns.forEach(function(column, index) {
            column.addEventListener('click', function() {
                var fileName = column.getAttribute('data-songname');
                playMusic(fileName, index);
            });
        });

        // 播放音乐
        function playMusic(fileName, index) {
            musicPlayer.src = "./MP3/" + fileName;
            musicPlayer.play();
            playPauseButton.textContent = "暂停";
            currentIndex = index;
            localStorage.setItem('currentIndex', currentIndex);
            currentSong.textContent = "正在播放：" + fileName;
            updatePlayMode();
            highlightCurrentSong();
        }

        // 暂停音乐【你干嘛哈哈哎哟】
        function pauseMusic() {
            musicPlayer.pause();
            playPauseButton.textContent = "播放";
        }

        // 切换播放/暂停状态 【微笑】
        function togglePlayPause() {
            if (musicPlayer.paused) {
                musicPlayer.play();
                playPauseButton.textContent = "暂停";
            } else {
                musicPlayer.pause();
                playPauseButton.textContent = "播放";
            }
        }

        // 播放上一首歌曲呀
        function playPrevious() {
            if (currentIndex > 0) {
                currentIndex--;
            } else {
                currentIndex = musicColumns.length - 1;
            }
            playMusic(musicColumns[currentIndex].getAttribute('data-songname'), currentIndex);
        }

        // 播放下一首
        function playNext() {
            if (currentIndex < musicColumns.length - 1) {
                currentIndex++;
            } else {
                currentIndex = 0;
            }
            playMusic(musicColumns[currentIndex].getAttribute('data-songname'), currentIndex);
        }

        // 搜索音乐功能
        function searchMusic() {
            var searchTerm = searchInput.value.toLowerCase().trim();
            var hasResults = false;
            var firstMatch = null;

            // 如果搜索框为空，恢复所有歌曲的显示状态
            if (searchTerm === '') {
                musicColumns.forEach(function(column) {
                    column.style.display = '';
                    column.style.backgroundColor = '';
                });
                searchResults.textContent = '';
                return;
            }

            musicColumns.forEach(function(column) {
                var musicFileName = column.getAttribute('data-songname').toLowerCase();
                // 移除文件扩展名进行搜索
                var musicName = musicFileName.replace(/\.[^/.]+$/, "");
                
                // 多条件匹配：完全匹配、包含关系、拼音首字母匹配
                if (musicName === searchTerm || 
                    musicName.includes(searchTerm) || 
                    musicFileName.includes(searchTerm)) {
                    
                    column.style.display = '';
                    column.style.backgroundColor = "rgba(255, 192, 203, 0.3)"; // 半透明粉色背景
                    
                    if (!firstMatch) {
                        firstMatch = column;
                    }
                    hasResults = true;
                } else {
                    column.style.display = 'none';
                    column.style.backgroundColor = '';
                }
            });

            // 显示搜索结果状态
            if (!hasResults) {
                searchResults.textContent = "未找到相关歌曲";
                searchResults.style.color = "#ff6b6b";
            } else {
                // 计算显示的结果数量
                var visibleCount = Array.from(musicColumns).filter(
                    column => column.style.display !== 'none'
                ).length;
                
                searchResults.textContent = `找到 ${visibleCount} 首相关歌曲`;
                searchResults.style.color = "#4ecdc4";

                // 平滑滚动到第一个匹配结果
                if (firstMatch) {
                    var container = document.querySelector('.music-container');
                    container.scrollTo({
                        top: firstMatch.offsetTop - container.offsetTop,
                        behavior: 'smooth'
                    });
                }
            }
        }

        // 添加实时搜索功能
        searchInput.addEventListener('input', debounce(searchMusic, 300));

        // 防抖函数
        function debounce(func, wait) {
            let timeout;
            return function executedFunction(...args) {
                const later = () => {
                    clearTimeout(timeout);
                    func(...args);
                };
                clearTimeout(timeout);
                timeout = setTimeout(later, wait);
            };
        }

        // 更新播放模式
        function updatePlayMode() {
            if (playMode === 'loop') {
                musicPlayer.loop = true;
            } else {
                musicPlayer.loop = false;
            }
        }

        // 改变播放模式
        function changePlayMode() {
            playMode = playModeSelect.value;
            localStorage.setItem('playMode', playMode);
            updatePlayMode();
        }

        // 高亮当前播放音乐
        function highlightCurrentSong() {
            musicColumns.forEach(function(column) {
                column.classList.remove('playing');
            });
            musicColumns[currentIndex].classList.add('playing');
        }

        // 初始化播放
        var savedIndex = localStorage.getItem('currentIndex');
        if (savedIndex !== null) {
            currentIndex = parseInt(savedIndex);
            var savedSong = musicColumns[currentIndex].getAttribute('data-songname');
            playMusic(savedSong, currentIndex);
        } else {
            var firstSong = musicColumns[0].getAttribute('data-songname');
            playMusic(firstSong, 0);
        }
        //版权所有 破天星辰科技网络 软件开发小组 2024 
    </script>
</body>
</html>

